package com.fbote.filter;


import java.io.IOException;


import javax.servlet.*;
import javax.servlet.http.*;

public class EncodingFilter implements Filter {
	protected FilterConfig filterConfig;
	private String encoding ;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		
		String forword = "/Fbote";		
		HttpServletRequest httprequest = (HttpServletRequest) request;
		HttpServletResponse httpresponse = (HttpServletResponse) response;
		HttpSession session = httprequest.getSession();
		request.setCharacterEncoding(encoding);
		response.setCharacterEncoding(encoding);		
		String url = httprequest.getRequestURL().toString();
		String s[] = url.split("/");
		String page = s[s.length - 1];
		System.out.println("============filter . page :" + page);
		chain.doFilter(request, response);
//		if (session.getAttribute("ctid") != null) {
//			chain.doFilter(request, response);
//			return;
//		} else {
//			if (page.equals("login.jsp")|| page.equals("login.do")||page.equals("Fbote")
//					|| page.substring(page.indexOf(".") + 1, page.length())
//							.equals("css")
//					|| page.substring(page.indexOf(".") + 1, page.length())
//							.equals("gif")
//					|| page.substring(page.indexOf(".") + 1, page.length())
//							.equals("jpg")
//					|| page.substring(page.indexOf(".") + 1, page.length())
//							.equals("bmp")	
//							|| page.substring(page.indexOf(".") + 1, page.length())
//							.equals("txt")	
//							
//			         ) {			
//				chain.doFilter(request, response);
//				return;
//			} else {
//				System.out.println("filter");
//				chain.doFilter(request, response);
////				httpresponse.sendRedirect(forword);
//				
//				return; 
//			}
//		}		
	}

	public void init(FilterConfig config) throws ServletException {
		this.encoding = config.getInitParameter("encoding");
		
	}
	  public void setFilterConfig(FilterConfig filterConfig)
	    {
	        this.filterConfig = filterConfig;
	    }

	    public void destroy()
	    {
	        filterConfig = null;
	    }
	

}
